/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// ptree.hpp - PegTreeView window class definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGTREE_
#define _PEGTREE_

class PegTreeView;

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegTreeNode : public PegTextThing
{
    friend class PegTreeView;

    public:
        PegTreeNode(PEGINT StringId = 0, PEGINT BmpId = 0);
        PegTreeNode(const PEGCHAR *pText, PEGINT BmpId = 0);

        virtual void Add(PegThing *pChild, PEGBOOL DoShow = FALSE);
        void AddAbove(PegThing *pChild, PEGBOOL DoShow = FALSE);
        PEGINT BranchHeight();
        PEGINT BranchWidth(PegTreeView *Parent);
        void Close(void) {mOpen = FALSE;}
        PEGINT Count(void);

        PegTreeNode *FirstNode(void) {return (PegTreeNode *) First();}
        void ForceOpen(void) {mOpen = TRUE;}
        PEGINT GetMap(void) {return mBitmapId;}

        void Insert(PegTreeNode *Sib);
        PEGBOOL IsOpen(void) {return mOpen;}
        PEGBOOL IsSelected(void) {return mSelected;}
        void MoveToTop(PegTreeNode *pChild);

        PegTreeNode *NextNode(void) {return (PegTreeNode *) Next();}
        PegTreeNode *NodeAbove(void);
        PegTreeNode *NodeBelow(void);
        PegTreeNode *NodeBottom(void);

        PEGINT NodeHeight();
        PEGINT NodeWidth();

        void Open(void) {if (First()) mOpen = TRUE;}
        PegTreeNode *ParentNode(void) {return (PegTreeNode *) Parent();}
        void SetMap(PEGINT BitmapId) {mBitmapId = BitmapId;}
        void SetNext(PegThing *Next) {mpNext = Next;}
        void SetSelected(PEGBOOL Selected){mSelected = Selected;}

    protected:

        PEGINT mBitmapId;
        PEGBOOL mOpen;
        PEGBOOL mSelected;
};



/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

class PegTreeView : public PegWindow
{
    public:
        PegTreeView(const PegRect &Rect, PEGINT StringId,
            PEGULONG Style, PEGINT BitmapId = 0);

        PegTreeView(const PegRect &Rect, const PEGCHAR *pText,
            PEGULONG Style, PEGINT BitmapId = 0);

        virtual ~PegTreeView();

        void DestroyNode(PegTreeNode *Who);
        virtual void Draw(const PegRect &Invalid);
        void DrawNode(PegTreeNode *pStart, PegPoint Put, PEGINT MaxMapWidth);
        PegTreeNode *FindNode(PEGINT Level, const PEGCHAR *Text);

        virtual void GetHScrollInfo(PegScrollInfo *Put);
        PEGINT GetIndent(void) {return mIndent;}
        PegTreeNode *GetSelected(void) {return mpSelected;}
        virtual void GetVScrollInfo(PegScrollInfo *Put);

        virtual PEGINT Message(const PegMessage &Mesg);
        PegTreeNode *RemoveNode(PegTreeNode *Who);
        void Reset(PEGINT TopStringId);
        void Reset(const PEGCHAR *pText);

        void Select(PegTreeNode *pWho);
        void SetIndent(PEGINT Val) {mIndent = Val;}
        virtual void ToggleBranch(PegTreeNode *);
        PegTreeNode *TopNode(void) {return mpTopNode;}



    protected:
        void CalcNodePositions(PegTreeNode* pStart, PegPoint Put,
                               PEGINT MaxMapWidth);
        PEGBOOL CheckNodeClick(PegPoint Click, PegTreeNode *pStart);

        void Construct(PEGINT StringId, const PEGCHAR *pText, PEGINT TopMap);

        PegTreeNode *FindSubNode(PegTreeNode *pTop, PEGINT CurLevel,
                                 PEGINT FindLevel, const PEGCHAR *pText);

        PegTreeNode *mpTopNode;
        PegTreeNode *mpSelected;
        PEGINT mTopOffset;
        PEGINT mLeftOffset;
        PEGINT mIndent;
        PEGINT mSearchLevel;
};



#endif

